#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "engctrlpanel.h"
#include "attitudepanel.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPalette palette(this->palette());
    palette.setColor(QPalette::Background, QColor(34,42,53,255));
    this->setPalette(palette);
    this->resize(700,500);

    eng = new EngCtrlPanel(this);
    eng->setEngValue(43,40,75);
    eng->resize(200,200);

    att = new AttitudePanel(this);
    att->resize(200,200);
    att->move(200,0);

    rpm = new EngRPMPanel(this);
    rpm->resize(200,200);
    rpm->move(400,0);

    taxi = new TaxiPanel(this);
    taxi->resize(200,200);
    taxi->move(0,200);

    //act = new ActorPanel(this);
    //act->resize(500,300);
    //act->move(200,200);

    hist = new HistoBottom(this);
    hist->resize(20,200);
    hist->move(200,200);

    his2 = new HistoMiddle(this);
    his2->resize(20,200);
    his2->move(230,200);


    timer = new QTimer(this);
    timer->stop();
    timer->setInterval (100) ;//设置定时周期，单位：毫秒
    timer->start();
    connect(timer,SIGNAL(timeout()),this,SLOT(on_timeout()));

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    int w = this->width();
    int h = this->height();
    eng->resize(w*2/7,h*2/5);
    att->resize(w*2/7,h*2/5);
    rpm->resize(w*2/7,h*2/5);
    taxi->resize(w*2/7,h*2/5);
    //act->resize(5*w/7,h*3/5);
    hist->resize(w*0.2/7,h*2/5);
    his2->resize(w*0.2/7,h*2/5);

}

void MainWindow::on_timeout()
{
    static float a = 0;
    static float b = 0;
    static float c = 0;
    static float d = 0;
    static float e = 0;
    static int f = 0;
    static float g = 0;
    static float h = 0;
    static float i=0;
    static float j=0;

    a+=1.0f;if(a>100.0)a=0;
    b+=2.0f;if(b>100.0)b=0;
    c+=1.5f;if(c>100.0)c=0;
    d+=1.0f;if(d>20.0)d=-20.0;
    e+=1.0f;if(e>45.0)e=-45.0;
    f+=13;if(f>3000)f=0;
    g+=1.0f;if(g>90.0)g=-90.0;
    h+=0.2f;if(h>20.0)h=-20.0;
    i+=2.3f;if(i>100.0)i=0;
    j+=3.0f;if(j>200.0)j=0;

    eng->setEngValue(a,b,c);
    att->setAttitudeValue(d,e);
    rpm->setRPMValue(f);
    taxi->setTaxiValue(g,h,i);
    hist->setValue(j);
    his2->setValue(100-j);

    eng->update();
    att->update();
    rpm->update();
    taxi->update();
    hist->update();
    his2->update();

    //qDebug()<<b;

}
